.TH std::has_facet 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::has_facet \- std::has_facet

.SH Synopsis
   Defined in header <locale>
   template< class Facet >                        \fI(until C++11)\fP
   bool has_facet( const locale& loc ) throw();
   template< class Facet >                        \fI(since C++11)\fP
   bool has_facet( const locale& loc ) noexcept;

   Checks if the locale loc implements the facet Facet.

   The program is ill-formed if Facet is not a facet or it is a volatile-qualified
   facet.

.SH Parameters

   loc - the locale object to query

.SH Return value

   Returns true if the facet Facet was installed in the locale loc, false otherwise.

.SH Notes

   std::has_facet must return true for all locales loc if Facet is one of the standard
   facets given here.

.SH Example


// Run this code

 #include <iostream>
 #include <locale>

 // minimal custom facet
 struct myfacet : public std::locale::facet
 {
     static std::locale::id id;
 };

 std::locale::id myfacet::id;

 int main()
 {
     // loc is a "C" locale with myfacet added
     std::locale loc(std::locale::classic(), new myfacet);
     std::cout << std::boolalpha
               << "Can loc classify chars? "
               << std::has_facet<std::ctype<char>>(loc) << '\\n'
               << "Can loc classify char32_t? "
               << std::has_facet<std::ctype<char32_t>>(loc) << '\\n'
               << "Does loc implement myfacet? "
               << std::has_facet<myfacet>(loc) << '\\n';
 }

.SH Output:

 Can loc classify chars? true
 Can loc classify char32_t? false
 Does loc implement myfacet? true

   Defect reports

   The following behavior-changing defect reports were applied retroactively to
   previously published C++ standards.

     DR    Applied to    Behavior as published               Correct behavior
   LWG 436 C++98      it was unclear whether Facet it can be const-qualified, but not
                      can be cv-qualified          volatile-qualified

.SH See also

   locale    set of polymorphic facets that encapsulate cultural differences
             \fI(class)\fP
   use_facet obtains a facet from a locale
             \fI(function template)\fP
